<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/14
 * Time: 16:00
 */

namespace app\admin\controller;
use app\admin\Controller;
use app\common\model\SetScore as modelSetScore;
\think\Loader::import('controller/Controller', \think\Config::get('traits_path'), EXT);

class SetScore extends Controller {

    use \app\admin\traits\controller\Controller;

    public function index() {
        if ($this->request->method() == "GET") {
            $keyword = $this->request->param();

            $where = [
                'isdelete' => 0,
            ];

            $model = new modelSetScore();
            $field = "id, type_name, score, create_time";
            $list = $model->getScoreInfoList($where, $field, $keyword, $this->request, 20);

            $this->view->assign('list', $list);
            $this->view->assign("count", $list->total());
            $this->view->assign("page", $list->render());
            $this->view->assign('numPerPage', $list->listRows());
        }
        return $this->view->fetch();
    }

    public function add () {

        if ($this->request->method() == "GET") {

        }

        return $this->view->fetch();
    }

    public function addScoreInfo () {
        if ($this->request->method() == "POST") {

            $param = $this->request->param();
            $param['create_time'] = date("Y-m-d H:i:s", time());
            $param['update_time'] = $param['create_time'];

            $model = new modelSetScore();

            $res = $model->addScoreInfo($param);
            if ($res) return ajax_return_adv("操作成功"); else return ajax_return_adv_error("操作失败");
        }
    }


    public function edit () {

        if ($this->request->method() == "GET") {

            $id = $this->request->param('id');

            $where = [
                'id' => $id,
                'isdelete' => 0
            ];

            $model = new modelSetScore();
            $field = "id, type_name, score";
            $data = $model->getScoreInfo($where, $field);

            $this->view->assign("vo", $data);
        }

        return $this->view->fetch();
    }

    public function updateScoreInfo (){

        if ($this->request->method() == "POST") {
            $param = $this->request->param();
            $where = [
                'id' => $param['id'],
                'isdelete' => 0
            ];
            $data = [
                'update_time' => date("Y-m-d H:i:s", time()),
                'type_name' => $param['type_name'],
                'score' => $param['score'],
            ];

            $model = new modelSetScore();
            $res = $model->updateScoreInfo($where, $data);
            if ($res) return ajax_return_adv("操作成功"); else return ajax_return_adv_error("操作失败");
            }
    }

    public function recyclebin() {
        if ($this->request->method() == "GET") {
            $keyword = $this->request->param();

            $where = [
                'isdelete' => 1,
            ];

            $model = new modelSetScore();
            $field = "id, type_name, score, create_time";
            $list = $model->getScoreInfoList($where, $field, $keyword, $this->request, 20);

            $this->view->assign('list', $list);
            $this->view->assign("count", $list->total());
            $this->view->assign("page", $list->render());
            $this->view->assign('numPerPage', $list->listRows());
        }
        return $this->view->fetch();
    }
}